package TCP.test1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;


/*
接收数据，写入文本文件
 */
public class SeverDemo {
    public static void main(String[] args) throws IOException {
        //创建服务器对象
        ServerSocket ss = new ServerSocket(10001);

        //监听客户端链接返回Socket
        Socket s = ss.accept();

        //接收数据
        BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
        BufferedWriter bw = new BufferedWriter(new FileWriter("JHX.txt"));

        String len;
        while ((len=br.readLine())!=null){
            bw.write(len);
            bw.newLine();
            bw.flush();
        }

        br.close();
        bw.close();
        ss.close();

    }

}

